/* RCU joystick control Mario Ninic */ int Stop = 0; int Fwd = 1; int Bwd = 2; int Left = 3; int Right = 4; int sensorY = A0; // select the input pin for the X potentiometer int sensorX = A1; // select the input pin for the Y potentiometer int sensorValue = 512; // variable to store the value coming from the sensor void setup() { Serial.setTimeout(500); // set serial timeout (ms) delay(200); Serial.begin(57600); Serial.println("Remote V 1.0. Mario Ninic"); } void loop() { // read the value from the Ysensor: sensorValue = analogRead(sensorY); if (sensorValue > 800){ RCU(Fwd); } else if (sensorValue < 200){ RCU(Bwd); } //RCU(Bwd);//Stop //delay(100); // read the value from the X sensor: sensorValue = analogRead(sensorX); if (sensorValue > 800){ RCU(Left); } else if (sensorValue < 200){ RCU(Right); } delay(50); } //function Control void RCU(int Motion){ switch (Motion){ case 0: //stop motor Serial.println("0"); break; case 1: //set direction and move fw Serial.println("1"); break; case 2: //move backward Serial.println("2"); break; case 3: //move left Serial.println("3"); break; case 4: //move right Serial.println("4"); default: delay(1); break; } }